var editor;
(function () {

    editor= CodeMirror.fromTextArea(document.getElementById("code"), {
        lineNumbers: true,
        theme: "night",
        matchBrackets: true,
        mode: "text/x-csrc",
        onCursorActivity: function() {
            editor.setLineClass(hlLine, null);
            hlLine = editor.setLineClass(editor.getCursor().line, "activeline");
        },
        onKeyEvent: function(i, e) {
            // Hook into F11
            if ((e.keyCode == 122 || e.keyCode == 27) && e.type == 'keydown') {
                e.stop();
                return toggleFullscreenEditing();
            }
        }
    });
    var hlLine = editor.setLineClass(0, "activeline");



    function toggleFullscreenEditing()
    {
        var editorDiv = $('.CodeMirror-scroll');
        if (!editorDiv.hasClass('fullscreen')) {
            toggleFullscreenEditing.beforeFullscreen = {
                height: editorDiv.height(), 
                width: editorDiv.width()
            }
            editorDiv.addClass('fullscreen');
            editorDiv.height('100%');
            editorDiv.width('100%');
            editor.refresh();
        }
        else {
            editorDiv.removeClass('fullscreen');
            editorDiv.height(toggleFullscreenEditing.beforeFullscreen.height);
            editorDiv.width(toggleFullscreenEditing.beforeFullscreen.width);
            editor.refresh();
        }
    }
    
    
   
    
    
})();

